class Node:
    def __init__(self, initdata):
        self.data = initdata  # 初始化节点的数据
        self.next = None  # 该节点目前没有指向任何其他节点

    def getdata(self):
        return self.data

    def getnext(self):
        return self.next

    def setdata(self, newdata):
        self.data = newdata

    def setnext(self, newnext):
        self.next = newnext


class UnorderedList:
    def __init__(self):
        self.head = None  # 链表的头节点初始化为None，表示初始状态下链表为空。

    def add(self, item):
        temp = Node(item)  # data:item | next:None
        temp.setnext(self.head)  # data:item | next:None
        self.head = temp  # 指向 本次添加的节点的位置

    def size(self):
        current = self.head
        count = 0
        while current is not None:
            count += 1
            current = current.getnext()
        return count

    def search(self, item):
        current = self.head
        found = False
        while current is not None and not found:
            if current.getdata() == item:
                found = True
            else:
                current = current.getnext()

        return found

    def remove(self, item):
        current = self.head
        previous = None
        found = False
        while not found:
            if current.getdata() == item:
                found = True
            else:
                previous = current
                current = current.getnext()
        if previous is None:
            # 首个节点，意思就是删除第一个节点 ，只需要将链表的表头
            # 节点设置为当前节点的下一个节点
            self.head = current.getnext()
        else:
            # 在链表的中间节点，需要实现将上一个节点的指向为当前节点的下一个节点，
            # 也就是跳过当前节点的关系
            previous.setnext(current.getnext())
